import json

from product_upload.util.supplier.giga_rpa_util import transform_data
from product_upload.util.basic.mysql_util import db_list_by_page, db_get_one, db_batch_update

# 第一次刷新rpa的gg数据
def flash_all_rpa_basic():
    for page in range(1, 99999):
        basic_gg_res = db_list_by_page("basic_gg", "*", "sku is null", page, 1000)
        if len(basic_gg_res) == 0:
            break
        for row in basic_gg_res:
            product_info = transform_data(row[4])
            print(row[0],row[1])
            sku = product_info.get("sku")
            price_info = json.loads(row[5])
            quantity = price_info.get('quantity')
            published = 0
            if price_info.get("price") > 0 and price_info.get("total_amount") > 0:
                published = 1
            price = price_info.get('price') + price_info.get("total_amount")
            prod = db_get_one("basic_product", f"sku='{sku}' and platform = 'GG'",None)
            if prod:
                db_batch_update("basic_product", ["id", "published", "price", "quantity"], [[prod[0], published, price, quantity]])
                db_batch_update("basic_gg", ["id", "sku", "origin_info"], [[row[0], sku, json.dumps(product_info)]])
if __name__ == '__main__':
    pass
